export default {
	onPullDownRefresh() {
		this.handlePullDownRefresh()
	},
	data() {
		return {
			triggered: false,
			_freshing: false
		}
	},
	methods: {
		handlePullDownRefresh() {
			// 刷新函数
			const refreshFunc = typeof this.handleRefresh === "function" ?
				'handleRefresh' :
				typeof this.init === "function" ? 'init' : null;
			if (!refreshFunc) {
				uni.stopPullDownRefresh()
				return;
			}
			//triggered，_freshing scroll-view 自定义刷新
			if (this._freshing) return;
			this._freshing = true;
			this.triggered = true
			this[refreshFunc]().then(res => {
				uni.showToast({
					duration: 1000,
					title: "刷新成功！",
					icon: "none"
				})
			}).catch(() => {
				uni.showToast({
					duration: 1000,
					title: "刷新失败！",
					icon: "none"
				})
			});
			//为避免下拉刷新loading和上拉加载的loading重复
			this.$nextTick(function() {
				this.triggered = false
				this._freshing = false
			})
			// 原生刷新
			uni.stopPullDownRefresh();
		}
	}
}
